//
//  MYTabBar.swift
//  NewMicroblog
//
//  Created by apple on 2016/10/22.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class MYTabBar: UITabBar {
    var closure:(()->())?
    override init(frame: CGRect) {
        super.init(frame: frame)
       
        setupUI()
    }
    
    /// 按钮点击执行此方法
    @objc private func btnClick(){
        closure?()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
   
    /// 设置UI界面
    private func setupUI()
    {
       addSubview(composeButton)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        let width : CGFloat = SCREENWIDTH * 0.2
        var idx :CGFloat = 0
        
        for value in subviews{
            NSClassFromString("")
            if value .isKind(of:NSClassFromString("UITabBarButton")! ) {
                value.frame.size.width = width
                value.frame.origin.x = idx * width
                idx += 1
                if idx == 2 {
                    idx += 1
                }
            }
            
        }
        composeButton.center.x = SCREENWIDTH * 0.5
        composeButton.center.y = frame.size.height * 0.5
    }
    
    /// 创建按钮添加点击事件
    var composeButton: UIButton = {
        let btn = UIButton(setImage: "tabbar_compose_icon_add", backgroundImage: "tabbar_compose_button", tagart: self, action: #selector(btnClick))
        return btn
    
    }()
}
